<template>
  <div class="banner-scroll">
    <!-- 第一行弹幕 -->
    <div class="scroll-row scroll-row-1">
      <div 
        v-for="(item, index) in danMuList1" 
        :key="`row1-${index}`"
        class="scroll-item"
        :style="{ '--delay': index * 0.5 + 's' }"
      >
        <img :src="item.avatar" :alt="item.content" class="user-avatar" />
        <span class="user-content">{{ item.content }}</span>
      </div>
      <!-- 重复一遍用于无缝滚动 -->
      <div 
        v-for="(item, index) in danMuList1" 
        :key="`row1-repeat-${index}`"
        class="scroll-item"
        :style="{ '--delay': index * 0.5 + 's' }"
      >
        <img :src="item.avatar" :alt="item.content" class="user-avatar" />
        <span class="user-content">{{ item.content }}</span>
      </div>
    </div>
    
    <!-- 第二行弹幕 -->
    <div class="scroll-row scroll-row-2">
      <div 
        v-for="(item, index) in danMuList2" 
        :key="`row2-${index}`"
        class="scroll-item"
        :style="{ '--delay': index * 0.5 + 's' }"
      >
        <img :src="item.avatar" :alt="item.content" class="user-avatar" />
        <span class="user-content">{{ item.content }}</span>
      </div>
      <!-- 重复一遍用于无缝滚动 -->
      <div 
        v-for="(item, index) in danMuList2" 
        :key="`row2-repeat-${index}`"
        class="scroll-item"
        :style="{ '--delay': index * 0.5 + 's' }"
      >
        <img :src="item.avatar" :alt="item.content" class="user-avatar" />
        <span class="user-content">{{ item.content }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  danMuList1: {
    type: Array,
    default: () => []
  },
  danMuList2: {
    type: Array,
    default: () => []
  }
})
</script>

<style scoped>
.banner-scroll {
  padding: 0 16px;
  margin-bottom: 20px;
  overflow: hidden;
}

.scroll-row {
  display: flex;
  align-items: center;
  white-space: nowrap;
  margin-bottom: 12px;
  animation-duration: 20s;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}

.scroll-row-1 {
  animation-name: scrollLeft;
}

.scroll-row-2 {
  animation-name: scrollRight;
  animation-direction: reverse;
}

.scroll-item {
  display: inline-flex;
  align-items: center;
  background-color: rgba(255, 255, 255, 0.9);
  padding: 8px 12px;
  border-radius: 20px;
  margin-right: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  transition: transform 0.3s ease;
  cursor: pointer;
  flex-shrink: 0;
}

.scroll-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  margin-right: 8px;
  object-fit: cover;
  border: 1px solid #e0e0e0;
}

.user-content {
  font-size: 14px;
  color: #333;
  font-weight: 500;
}

@keyframes scrollLeft {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

@keyframes scrollRight {
  0% {
    transform: translateX(-50%);
  }
  100% {
    transform: translateX(0);
  }
}

/* 暂停动画在悬停时 */
.scroll-row:hover {
  animation-play-state: paused;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .banner-scroll {
    padding: 0 12px;
    margin-bottom: 16px;
  }
  
  .scroll-row {
    margin-bottom: 8px;
    animation-duration: 15s;
  }
  
  .scroll-item {
    padding: 6px 10px;
    margin-right: 8px;
  }
  
  .user-avatar {
    width: 20px;
    height: 20px;
    margin-right: 6px;
  }
  
  .user-content {
    font-size: 12px;
  }
}
</style>
